<?=view('admin.common.header')?>
<?=view('admin.common.nav')?>
<?=view("admin.common.datetimepicker")?>
<div class="container">
    <div class="row">
        <ul class="nav nav-pills" style="margin-bottom: 20px;">
            <li role="presentation"><a href="<?=url('admin/order/index')?>?status=0">未付款订单</a></li>
            <li role="presentation"><a href="<?=url('admin/order/index')?>?status=1">完成付款未处理订单</a></li>
            <li role="presentation"><a href="<?=url('admin/order/index')?>?status=2">已关闭订单</a></li>
            <li role="presentation"><a href="<?=url('admin/order/index')?>?status=3">已开户订单</a></li>
            <li role="presentation"><a href="<?=url('admin/order/index')?>?status=4">已续费订单</a></li>
        </ul>
        <?php if (in_array('report', config("adminuser.permission.".session('admin.name')))):?>
        <form class="form-inline" style="margin-bottom: 15px;" action="<?=url('admin/order/report')?>" target="_blank">
            <div class="form-group">
                <select class="form-control" name="plot">
                    <option value="">--请选择小区--</option>
                    <?php foreach ($plots as $plot): ?>
                    <option value="<?=$plot->id?>" <?php if ($plot->id == $request->input("plot")): ?>selected="selected"<?php endif; ?>><?=$plot->name?></option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="form-group">
                <select class="form-control" name="ptype">
                    <option value="" <?php if (empty($request->input("ptype", ''))): ?>selected="selected"<?php endif; ?>>所有</option>
                    <option value="1" <?php if ($request->input("ptype") == 1): ?>selected="selected"<?php endif; ?>>新装</option>
                    <option value="2" <?php if ($request->input("ptype") == 2): ?>selected="selected"<?php endif; ?>>续费</option>
                </select>
            </div>
            <div class="form-group">
                <div class="input-group date form_date_start">
                    <input class="form-control" name="starttime" size="16" type="text" value="<?=$request->input('starttime', '')?>" readonly="" placeholder="查新开始日期">
                    <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                </div>
            </div>
            <div class="form-group">
                <div class="input-group date form_date_end">
                    <input class="form-control" name="endtime" size="16" type="text" value="<?=$request->input('endtime', '')?>" readonly="" placeholder="查新结束日期">
                    <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                </div>
            </div>
            <div class="form-group">
                <input type="submit" class="btn btn-info" value="查 询">
            </div>
        </form>
        <script>
            $('.form_date_start').datetimepicker({
                format: 'yyyy-mm-dd hh:ii:ss',
                language:  'zh-CN',
                weekStart: 1,
                todayBtn:  1,
                autoclose: 1,
                todayHighlight: 1,
                startView: 2,
                minView: 0,
                forceParse: 0
            }).on('changeDate', function(ev){
                if ($('input[name=endtime]').val() != '') {
                    var endtime = new Date($('input[name=endtime]').val());
                    if (ev.date.valueOf() > endtime.valueOf()) {
                        $('input[name=starttime]').val('');
                        alert("开始日期必须小于结束日期");
                    }
                }
            });
            $('.form_date_end').datetimepicker({
                format: 'yyyy-mm-dd hh:ii:ss',
                language:  'zh-CN',
                weekStart: 1,
                todayBtn:  1,
                autoclose: 1,
                todayHighlight: 1,
                startView: 2,
                minView: 0,
                forceParse: 0
            }).on('changeDate', function(ev){
                if ($('input[name=starttime]').val() == '') {
                    alert("请选择开始日期");
                }
                var endtime = new Date($('input[name=starttime]').val());
                if (ev.date.valueOf() < endtime.valueOf()) {
                    $('input[name=starttime]').val('');
                    alert("开始日期必须小于结束日期");
                }
            });
        </script>
        <?php endif; ?> 
        <?php if($orders && count($orders)): ?>
        <div class="panel panel-default">
            <div class="panel-heading">
                订单列表
            </div>
            <table class="table table-bordered">
                <thead>
                    <tr>
                        <th>订单号</th>
                        <th>订单时间</th>
                        <th>微信昵称</th>
                        <th>客户姓名</th>
                        <th>联系电话</th>
                        <th>订单金额</th>
                        <th>订单状态</th>
                        <th>订单类型</th>
                        <th>#</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($orders as $val): ?>
                    <tr>
                        <td><?=$val->order?></td>
                        <td><?=$val->strTime()?></td>
                        <td><?=$val->wxNickName()?></td>
                        <td><?=$val->name?></td>
                        <td><?=$val->phone?></td>
                        <td><?=$val->strPrice()?></td>
                        <td><?=$val->strStatus()?></td>
                        <td><?=$val->strProductType()?></td>
                        <td>
                            <a href="#" data-info="<?=$val->id?>" class="btn btn-info btn-xs eveInfo">查看详情</a>
                            <table class="table" id="info<?=$val->id?>" style="display: none;">
                                <tr>
                                    <td>装机小区</td>
                                    <td><?=$val->strPlot()?></td>
                                </tr>
                                <tr>
                                    <td>装机详细地址</td>
                                    <td><?=$val->address?></td>
                                </tr>
                                <tr>
                                    <td>商品名称-类型</td>
                                    <td><?=$val->strProduct()?></td>
                                </tr>
                                <tr>
                                    <td>用户身份证信息</td>
                                    <td>
                                        <?=$val->cardnumber?>
                                        <p class="help-block">(请在开户时候将该订单的用户证件另存到电脑上，与开户信息放在一起作为实名认证的信息)</p>
                                    </td>
                                </tr>
                                <?php if ($val->status == 3): ?>
                                <tr>
                                    <td>上网帐号/密码</td>
                                    <td><?=$val->strNetUser()?></td>
                                </tr>
                                <?php elseif ($val->status == 4): ?>
                                <tr>
                                    <td>续费帐号</td>
                                    <td><?=$val->strNetUser()?></td>
                                </tr>
                                <?php endif; ?>
                                <tr>
                                    <td>付款完成时间</td>
                                    <td><?=$val->strPayTime()?></td>
                                </tr>
                                <?php if ($val->admintime): ?>
                                <tr>
                                    <td>后台操作时间</td>
                                    <td><?=$val->strAdminTime()?></td>
                                </tr>
                                <?php endif; ?>
                            </table>
							<?php if (in_array($val->status, array(0)) && $val->issub == 0): ?>
							<a href="<?=url("admin/order/edit/{$val->id}/0")?>" class="btn btn-success btn-xs eveMod">修改价格</a>
							<?php endif; ?>
                            <?php if (in_array($val->status, array(0))): ?>
                            <a href="<?=url("admin/order/edit/{$val->id}/2")?>" class="btn btn-danger btn-xs eveDel">关闭订单</a>
                            <?php endif; ?>
                            <?php if (in_array($val->status, array(2))): ?>
                            <a href="<?=url("admin/order/del/{$val->id}")?>" class="btn btn-danger btn-xs eveDel">删除</a>
                            <?php endif; ?>
                            <?php if (in_array($val->status, array(1)) && $val->type==1): ?>
                            <a href="<?=url("admin/order/edit/{$val->id}/3")?>" class="btn btn-primary btn-xs evekh">开 户</a>
                            <a href="<?=url("admin/jobs/add?oid={$val->id}")?>" target="_blank" class="btn btn-primary btn-xs">派 单</a>
                            <?php endif; ?>
                            <?php if (in_array($val->status, array(1)) && $val->type==2): ?>
                            <a href="<?=url("admin/order/edit/{$val->id}/4")?>" class="btn btn-warning btn-xs evexf">续 费</a>
                            <a href="<?=url("admin/jobs/add?oid={$val->id}")?>" target="_blank" class="btn btn-warning btn-xs">派 单</a>
                            <?php endif; ?>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
        <?php if ($append && count($append)): ?>
        <?=$orders->appends($append)->render()?>
        <?php else: ?>
        <?=$orders->render()?>
        <?php endif; ?>
        <?php endif; ?>
    </div>
</div>
<script>
$(".eveInfo").click(function(){
    var infoid = '#info'+$(this).attr('data-info');
    layer.open({
        type: 1,
        title: '订单详情',
        shadeClose: true,
        shade: 0.8,
        area: ['80%', '60%'],
        content:  $(infoid),
    });
    return false;
});
$('.eveDel').click(function(){
    var url = $(this).attr('href');
    $.get(url, function(data){
       layer.msg(data.info);
       if (data.status == 1) {
           window.location.reload();
       }
    });
    return false;
});
$('.evexf,.evekh,.eveMod').click(function(){
    var url = $(this).attr('href');
    layer.open({
        type: 2,
        title: '信息',
        shadeClose: false,
        shade: 0.8,
        area: ['380px', '300px'],
        content:  url,
    });
    return false;
});
var msg = '<?=$msg?>';
if (msg != '') {
    layer.msg(msg);
}
</script>
<?=view('admin.common.footer')?>